const app = getApp();
const Controller = require('../controllers/controllers.js').controller;
const WxParse = require('../Common/wxParse/wxParse.js');
Page({
  data: {
    id:'',
    detaildata:'',
    content:'',
    type:1,
    page:1,
    pageSize:10,
    isEnd:false,
    listsdata:[],
    ismore:true
  },
  onLoad: function (option) {
    if(option.id){
      this.setData({
        id:option.id
      })
      this.goodsDetail()
      this.contentlist()
    }
  },
  golink(e){
    wx.navigateTo({
      url:e.currentTarget.dataset.url
    });
  },
  more(){
    this.setData({
      ismore:!this.data.ismore
    })
  },
  toLocation(e){
    var lng=e.currentTarget.dataset.lng;
    var lat=e.currentTarget.dataset.lat;
    var name=e.currentTarget.dataset.name;
    var address=e.currentTarget.dataset.address;
    wx.openLocation({
    //当前经纬度
      latitude: Number(lat),
      longitude: Number(lng),
      //缩放级别默认28
      scale: 28,
      //位置名
      name: name,
      //详细地址
      address: address,
      //成功打印信息
      success: function(res) {
          console.log(res)
      },
      //失败打印信息
      fail: function(err) {
          console.log(err)
      },
      //完成打印信息
      complete: function(info) {
          console.log(info)
      },
    })
  },
  goodsDetail(){
    Controller.companydetail({companyId:this.data.id}).then(res=>{
      if(res.data.baseData){
        if(res.data.baseData.dormitoryImgUrls){
          res.data.baseData.dormitoryImgUrls=res.data.baseData.dormitoryImgUrls.split(',')
        }
        if(res.data.baseData.workImgUrls){
          res.data.baseData.workImgUrls=res.data.baseData.workImgUrls.split(',')
        }
        if(res.data.baseData.companyImgUrls){
          res.data.baseData.companyImgUrls=res.data.baseData.companyImgUrls.split(',')
        }
        if(res.data.baseData.otherImgUrls){
          res.data.baseData.otherImgUrls=res.data.baseData.otherImgUrls.split(',')
        }
        if(res.data.baseData.canteenImgUrls){
          res.data.baseData.canteenImgUrls=res.data.baseData.canteenImgUrls.split(',')
        }
        if(res.data.baseData.entertainmentImgUrls){
          res.data.baseData.entertainmentImgUrls=res.data.baseData.entertainmentImgUrls.split(',')
        }
        this.setData({
          detaildata:res.data.baseData
        })
        if(res.data.baseData.desc){
          var content=res.data.baseData.desc
          var that = this;
          WxParse.wxParse('content', 'html', content, that, 5);
          res.data.baseData.desc = JSON.stringify(res.data.baseData.desc).replace(/<img/gi, "<img class='richImg' style='width:auto!important;height:auto!important;max-height:100%;width:100%;'");
          res.data.baseData.desc = JSON.parse(res.data.baseData.desc);
        }
      }
    })
  },
  tabs(e){
    this.setData({
      type:e.currentTarget.dataset.type,
      // page:1,
      // pageSize:10,
      // isEnd:false,
      // listsdata:[],
    })
    // this.contentlist()
  },
  contentlist(){
    var data={
      keyword:"",
      isHot:'',
      page:this.data.page,
      pageSize:this.data.pageSize,
      companyId:this.data.id,
      city:''
    }

    Controller.joblist(data).then(res=>{
      if(res.data.baseData && res.data.baseData.list.length>0){
        this.setData({
          listsdata:this.data.listsdata.concat(res.data.baseData.list),
        })
      }
      if(res.data.baseData.lastPage){
        this.setData({
          isEnd:res.data.baseData.lastPage
        })
      }
      this.setData({
        isloading:false
      })
    })
    
  },
  onReachBottom(){
    if(this.data.isEnd){
      return
    }else{
      this.setData({
        page:this.data.page+1
      })
      this.contentlist()
    }
    
  },
  previewImage(e){
    console.log(e.currentTarget.dataset.url)
    var urls=[];
    var dormitoryImgUrls=this.data.detaildata.dormitoryImgUrls || [];
    var workImgUrls=this.data.detaildata.workImgUrls || [];
    var companyImgUrls=this.data.detaildata.companyImgUrls || [];
    var otherImgUrls=this.data.detaildata.otherImgUrls || [];
    var canteenImgUrls=this.data.detaildata.canteenImgUrls || [];
    var entertainmentImgUrls=this.data.detaildata.entertainmentImgUrls || [];
    urls=urls.concat(companyImgUrls,workImgUrls,dormitoryImgUrls,canteenImgUrls,entertainmentImgUrls,otherImgUrls)


    wx.previewImage({
      current: e.currentTarget.dataset.url, // 当前显示图片的http链接
      urls:urls, // 需要预览的图片http链接列表
    })
  },
  onShareAppMessage: function (e) {
    
  },
  onShareTimeline: function(res){
    
  },
 
})